export function getDate(n : number = 0) {
    const today = setDate(n)
    let year = today.getFullYear();
    let month = paddingWithZeros(today.getMonth() + 1)
    let day = paddingWithZeros(today.getDate())
    return `${year}-${month}-${day}`
}

export function getDateTime(n = 0, options : any = { start: false, end: false }) {
    const today = setDate(n)
    let year = today.getFullYear();
    let month = paddingWithZeros(today.getMonth() + 1)
    let day = paddingWithZeros(today.getDate())
    let hour = options?.start ? '00' : (options?.end ? '23' : paddingWithZeros(today.getHours()))
    let minute = options?.start ? '00' : (options?.end ? '59' : paddingWithZeros(today.getMinutes()))
    let second = options?.start ? '00' : (options?.end ? '59' : paddingWithZeros(today.getSeconds()))
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`
}

export function setDate(n : number = 0) {
    const date = new Date()
    let targetday_milliseconds = date.getTime() + 1000 * 60 * 60 * 24 * n
    date.setTime(targetday_milliseconds)
    return date
}

export function paddingWithZeros(data : number | string) : any {
    var m = data.toString()
    if (m.toString().length == 1) {
        m = "0" + m;
    }
    return m
}